// pages/dealer-service/insurance-report/insurance-report.js
const SERVICE = require("../../lib/js/service.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showNoData: true,
    agreement: {
      show: false,
      quit: "AgreementQuit",
      consent: "AgreementQuit"
    },
    reportList: [
      {
        time: '2010-08-18',
        price: '63707',
        priceList: [
          { label: '出险', content: '63707' },
          { label: '维修', content: '3200' },
          { label: '换件', content: '60507' },
          { label: '其他', content: '63707' }
        ],
        detailList: [
          {
            type: '维修',
            list: [
              { name: '前保险杠（全喷）', price: '459' },
              { name: '后保险杠（全喷）', price: '459' },
              { name: '右后叶子板（全喷）', price: '459' },
              { name: '右前叶子板（全喷）', price: '408' },
              { name: '前保险杠（全喷）', price: '459' }
            ]
          },
          {
            type: '换件',
            list: [
              { name: '排气管尾节1', price: '1609' },
              { name: '排气管尾节2', price: '2207' },
              { name: '后围', price: '1350' },
              { name: '副驾驶员座椅安全带', price: '1140' }
            ]
          }
        ]
      },
      {
        time: '2014-03-26',
        price: '5280',
        priceList: [
          { label: '出险', content: '5280' },
          { label: '维修', content: '4070' },
          { label: '换件', content: '1210' },
          { label: '其他', content: '0' }
        ],
        detailList: [
          {
            type: '维修',
            list: [
              { name: '前保、机盖、左右前叶、左前纵梁', price: '2250' },
              { name: '前保险杠骨架', price: '1120' },
              { name: '变速器冷却器进油管', price: '230' },
              { name: '前大灯安装底板（右）', price: '470' }
            ]
          },
          {
            type: '换件',
            list: [
              { name: '前保险杠下隔栅', price: '710' },
              { name: '前杠下中网', price: '350' },
              { name: '发动机罩铰链（左）', price: '150' }
            ]
          }
        ]
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this;
    wx.showNavigationBarLoading();
    SERVICE.POST(SERVICE.URL.show4SReports,{
      orderId: options.id
    },(status,res)=>{
      console.log(res);
      wx.hideNavigationBarLoading();
      if(res.data.status == "success"){
        let Reports = res.data;
        let carClaimRecords = Reports.data.carClaimRecords;

        for (let i = 0; i < carClaimRecords.length; i++){
          
          let array = [{ type: "", data: [] }, { type: "", data: [] }];

          for (let e = 0; e < carClaimRecords[i].claimDetails.length; e++){
            if (carClaimRecords[i].claimDetails[e].itemType == "维修"){
              array[0].type = "维修";
              array[0].data.push(carClaimRecords[i].claimDetails[e]);
              carClaimRecords[i].list = array;

            } else if (carClaimRecords[i].claimDetails[e].itemType == "换件"){
              // array[1] = {type: "", data:[]};
              array[1].type = "换件";
              array[1].data.push(carClaimRecords[i].claimDetails[e]);
              carClaimRecords[i].list = array;
              // console.log(i);
            }
          }
        }
        Reports.carClaimRecords = carClaimRecords;
        console.log(Reports);
        
        _this.setData({
          Reports,
              
        });
      }else{
        _this.setData({
          showNoData: false    
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  AgreementQuit() {
    let td = this.data;
    td.agreement.show = false;
    this.setData({
      agreement: td.agreement
    });
  },
  viewAgreement(){
    let td = this.data;
    td.agreement.show = true;
    this.setData({
      agreement: td.agreement
    });
  }
})